package fm.dongman.animefm.view.adapter;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import fm.dongman.animefm.R;
import java.util.List;
import fm.dongman.animefm.contractlib.IModel;
import fm.dongman.animefm.view.activity.SingleActivity;
import fm.dongman.animefm.view.util.ActivityHelper;
import fm.dongman.animefm.view.util.ToastHelper;
import fm.dongman.modellib.model.CommentModel;

import static fm.dongman.animefm.view.activity.SingleActivity.Companion;

/**
 * 他人评论，我的评论适配器
 * Created by Administrator on 2017/11/26.
 */

public class CommentListAdapter extends RecyclerView.Adapter<CommentListAdapter.ViewHolder>{
    private List<IModel.ICommentModel> mCommentList;
    private Context mContext;

    public CommentListAdapter(Context Context, List<IModel.ICommentModel> CommentList){
        mCommentList=CommentList;
        mContext=Context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(mContext).inflate(R.layout.item_comment_nopic_listl,null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        final CommentModel comment= (CommentModel) mCommentList.get(position);
        holder.mComicTitle.setText(comment.getTitle());
        holder.mComicTime.setText(comment.getCreateTime());
        holder.mComicContent.setText(comment.getContent());


        holder.mComicTitle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mContext instanceof Activity) {
                    Intent intent = new Intent(mContext, SingleActivity.class);
                    intent.putExtra(Companion.getEXTRA_NAME(), Companion.getINTENT_EXTRA_ANIME_INFO());
                    intent.putExtra(Companion.getBUNDLE_EXTRA_KEY_ID(), comment.getSubjectId());

                    ActivityHelper.INSTANCE.startActivity((Activity) mContext, intent);
                } else {
                    throw new RuntimeException(mContext.toString() + "必须是Activity!");
                }
            }
        });
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              //  ToastHelper.getInstance(mContext).showSucceed("评论");
            }
        });
    }

    @Override
    public int getItemCount() {
        return mCommentList.size();
    }


    public class ViewHolder extends RecyclerView.ViewHolder {
        private TextView mComicTitle;
        private TextView mComicTime;
        private TextView mComicContent;
        private int mComicId;

        public ViewHolder(View itemView) {
            super(itemView);
            mComicTitle= (TextView) itemView.findViewById(R.id.mTvProductionTextNo);
            mComicTime= (TextView) itemView.findViewById(R.id.mTvTheLatestCommentsTimeNo);
            mComicContent= (TextView) itemView.findViewById(R.id.mTvTheLatestCommentsNo);
        }
    }
}
